package com.lance.answer.question_answer.xj_new;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lance.answer.dto.GkUser;
import com.lance.answer.gui.answer.AnswerObject;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author fengx
 * 获取新疆一体化 每个学生的刷题信息
 */
public class GetXjStudentSituation {





    public static void main(String[] args) throws IOException {


//        int sum = 0 ;
//        for(File file1:new File("E:\\xjStudentInfo2022\\deal").listFiles()){
//    //    for(File file1:new File("E:\\XjStudentCourseInfoTmp\\names").listFiles()){
//            InputStream inputStream1 = new FileInputStream(file1);
//            List<String> list = JSONObject.parseArray( IOUtils.toString(inputStream1, StandardCharsets.UTF_8), String.class);
//            System.err.println("listSize:"+list.size());
//            sum+=list.size();
//        }
//        System.out.println("sum:"+sum);
//        try {
//            Thread.sleep(200000000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }


        /**
         * 310225198902143818.json
         * 现在统计是有问题的，有的课程 平时作业 刷了 但是还是显示没有刷........
         * {
         * 					"ruleName":"测验",
         * 					"ruleTotal":12,
         * 					"studyCount":12
         *                                },
         *                {
         * 					"ruleName":"在线作业",
         * 					"ruleTotal":4,
         * 					"studyCount":0
         *                }
         *                一定程度上会影响判断了...............
         */
        int sync = 16;

        File file= new File("E:\\xjStudentInfo2022\\origin");

        List<String> names = Lists.newArrayList();
        for(File file1:file.listFiles()){

          //  if(file1.length()<1024){
            if(file1.length()<2){
                continue;
            }

            String file1Name = file1.getName();
            System.err.println(file1Name);
            names.add(file1Name.substring(0,file1Name.length()-5));
        }

        List<String> unDoneNames = Lists.newArrayList();
        for(File file1:new File("E:\\xjStudentInfo2022\\undone").listFiles()){
            String file1Name = file1.getName();
            unDoneNames.add(file1Name.substring(0,file1Name.length()-5));
        }


      //  InputStream inputStream3 = new FileInputStream("E:\\alluser.txt");
        InputStream inputStream3 = new FileInputStream("E:\\alluser.txt");
        List<String> users = IOUtils.readLines(inputStream3, "utf-8");

        LinkedBlockingDeque<GkUser> usersQueue = new LinkedBlockingDeque<>();


        Map<String,String> userMap = Maps.newHashMap();
        for(String username:users){
            String[] strs = username.split(",");
            userMap.put(strs[0],strs[1]);
        }

        for(String username:userMap.keySet()){
             if(names.contains(username)&&!unDoneNames.contains(username)){
       //     if(names.contains(username)){
                continue;
            }
//            if(!username.equals("652924199811050073")){
//                continue;
//            }

            String pwd = userMap.get(username);
            if (pwd.length() > 14) {
                if (pwd.contains("X")||pwd.contains("x")) {
                    pwd = pwd.substring(11, 17);
                } else {
                    pwd = pwd.substring(12);
                }
            }


            GkUser gkUser = new GkUser();
            gkUser.setUsername(username);
            gkUser.setPwd(pwd);
            //   videoDto.setSubjectCode(subjectCode);

            usersQueue.add(gkUser);
        }


        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new GetXjStudentSituationTask(null,usersQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName( "答题线程--" + i);
            answerThread.start();
        }



    }


    //   WebDriver driver = Util.getDriver("d:\\ynouAutoStudy\\chromedriver.exe");


}














